﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="placeUC.ascx.cs" Inherits="MobiMap.Admin.placeUC" %>

<link rel="Stylesheet" href="../Style/AdminStyle.css" type="text/css" />

<script type="text/javascript" src="../Script/AdminScript.js" ></script>  
<script type="text/javascript">
    var txtAddressValue = "";
    function txtAddressFocus()
    {
        txtAddressValue = document.getElementById('<%=txtService_Address.ClientID %>').value;
    }
    //Lay vi tri cua dia chi do nguoi dung nhap vao
    function GetPosition(me)
    {        
        if(me.value != txtAddressValue && me.value != "") //neu thay doi gia tri
        {
            var cmb = document.getElementById('<%=cmbPlaceType.ClientID %>');        
            var placeType = cmb.options[cmb.selectedIndex].value;
            
            necessaryData = "PlacePoint@" + placeType + "@" + me.value;
            var url = "newcenter=address" + "@" + me.value; 
            LoadMap(url);            
        }
    }
    
    
    //Lay toa do latitude, longitude do nguoi dung nhap vao
    var errorLat = false;
    var errorLong = false;
    var errorFullName = false;
    var errorAddress = false;
    
    function checkFullName()
    {
        var node = document.getElementById('<%=txtService_FullName.ClientID%>');
        if(node.value == "") {
            showError(node);
            errorFullName = true;
        }
        else {
            fixError(node);    
            errorFullName = false;
        }
    }
    
    function checkAddress()
    {
        var node = document.getElementById('<%=txtService_Address.ClientID%>');
        if(node.value == "")  {
            showError(node);
            errorAddress = true;
        }
        else {
            fixError(node);
            errorAddress = false;
        }
    }
    
    function checkLatLong()
    {
        var latNode = document.getElementById('<%=txtService_Latitude.ClientID%>');
        var longNode = document.getElementById('<%=txtService_Longitude.ClientID%>');
        var latitude = parseFloat(latNode.value);
        var longitude = parseFloat(longNode.value);
        
        if(isNaN(latitude) || latitude<-90 || latitude>90) {
            showError(latNode);
            errorLat = true;
        }
        else {
            fixError(latNode);
            errorLat = false;
        }
        
        if(isNaN(longitude) || longitude<-180 || longitude>180) {
            showError(longNode);
            errorLong = true;
        }
        else {
            fixError(longNode); 
            errorLong = false;           
        }
        
        var strReturn = latitude + "@" + longitude;
        return strReturn;
    }
    
    function LatLongChange()
    {           
        var latlong = checkLatLong();
        
        if(errorLat == false && errorLong == false)
        {
            necessaryData = "PlacePoint";            
            var res = "newcenter=latlong" + "@" + latlong;
            
            LoadMap(res);            
        }        
        
        return false;
    }
    
    function showError(node)
    {
        node.style.backgroundColor = "#FDBCAC";
    }
    
    function fixError(node)
    {
        node.style.backgroundColor = "White";
    }
        
    function GetDataFromServer(evtAgrs)
    {        
        var arrData = evtAgrs.split("@");
        if(arrData[0] == "PlacePoint")
        {
            var flagNode = document.getElementById("imgFlag");
            var newleft = parseInt(arrData[1]) - 11;
            var newtop = parseInt(arrData[2]) - 34;
            if(newleft > 0 && newleft < mapSize && newtop > 0 && newtop < mapSize)
            {
                flagNode.style.left = newleft + "px";
                flagNode.style.top = newtop + "px";
                flagNode.style.display = "block";
                flagVisible = true;
            }
            
            //Neu co diem trung nha
            if(arrData.length > 3)                
            {
                document.getElementById("divSamePlace").style.display = "block";
                var places = document.getElementById("places");
                places.innerHTML = "";
                
                var s;
                for(var i=3; i<arrData.length;  i++)
                {
                    s = arrData[i].split("$");
                    var innerCode = "- <b onclick=\"viewServiceDetail('hdd" + i + "')\">" + s[0] + ", " + "</b>"  + s[1]
                                    + "<input type='hidden' id='hdd" + i + "' value='" + s[2] + "'/>";
                    
                    places.innerHTML += innerCode + "<br>";
                }                
            }            
            else
            {
                document.getElementById("divSamePlace").style.display = "none";
            }
        }
        else if(arrData[0] == "PlaceCoor")
        {
            var latNode = document.getElementById("<%=txtService_Latitude.ClientID%>");
            latNode.value = arrData[1];
            fixError(latNode);
            
            var longNode = document.getElementById("<%=txtService_Longitude.ClientID%>");
            longNode.value = arrData[2];
            fixError(longNode);
        }
              
    }
    
    function viewServiceDetail(hddID)
    {
        window.location = "ServiceDetail.aspx?ID=" + document.getElementById(hddID).value;
    }
    
    function changePlaceType()
    {
        var cmb = document.getElementById('<%=cmbPlaceType.ClientID %>');        
        var placeType = cmb.options[cmb.selectedIndex].value;
        var placeAddress = document.getElementById('<%=txtService_Address.ClientID %>').value;
        
        if(placeAddress != "")
        {
            necessaryData = "PlacePoint@" + placeType + "@" + placeAddress;
            CallServer(necessaryData);
        }
    }
        
</script>

<div align="left">
<br />
<table style="font-size: 12px;" cellspacing="5px">
    <tr>
        <td><label id="lbPlaceName" runat="server">Tên dịch vụ</label></td>
        <td>
            <input type="text" runat="server" id="txtService_FullName" class="longTextBox" />
            <label>*<br />
            </label>
        </td>        
    </tr>
    <tr>
        <td><label id="lbPlaceType" runat="server">Danh mục</label></td>
        <td>
            <asp:DropDownList runat="server" ID="cmbPlaceType" CssClass="cmbPlaceType"/>
            <label>*</label>
        </td>
    </tr>
    <tr valign="top">
        <td><label id="lbAddress" runat="server">Địa chỉ</label></td>
        <td>
            <input class="longTextBox" runat="server" type="text" id="txtService_Address" 
                onfocus="txtAddressFocus()"  onblur="return GetPosition(this);"/>
            <label>*</label>
            <div id="divSamePlace" class="sameplace">
                <lb id="lbSamePlaces" runat="server">Địa điểm này có thể trùng với</lb>:<br />
                <div id="places"></div>
            </div>
        </td>
    </tr>
    
    <tr>
        <td><label id="lbLatitude" runat="server">Vĩ độ</label></td>
        <td>
            <input class="shortTextBox" runat="server" type="text" id="txtService_Latitude" maxlength="12"/>
            <label>*</label>
        </td>
    </tr>
    <tr>
        <td><label id="lbLongitude" runat="server">Kinh độ</label></td>
        <td>
            <input class="shortTextBox" runat="server" type="text" id="txtService_Longitude" maxlength="12"/>
            <label>*</label>
            <asp:LinkButton ID="showInMap" CssClass="showInMap" runat="server" OnClientClick="return LatLongChange();" Text="Hiện điểm này trên bản đồ"></asp:LinkButton>
        </td>
    </tr>
    <tr>
        <td><label id="lbPhone" runat="server">Điện thoại</label></td>
        <td><input runat="server" type="text" class="longTextBox" id="txtService_Phone" /></td>
    </tr><tr>
        <td><label id="lbWebsite" runat="server">Website</label></td>
        <td><input runat="server" type="text" id="txtService_Website" class="longTextBox"/></td>
    </tr>
    <tr>
        <td><label id="lbPicture" runat="server">Hình ảnh</label></td>
        <td><input runat="server" type="file" id="txtService_Picture" size="30"/></td>
    </tr>
    <tr>
        <td><label id="lbDescription" runat="server">Mô tả</label></td>
        <td><textarea runat="server" rows="3" cols="35" id="txtService_Info"></textarea></td>
    </tr>
    
</table>
</div>
